snapshot: Export gtk_snapshot_append_layout()
authorBenjamin Otte <otte@redhat.com>
Mon, 26 Mar 2018 02:23:11 +0000 (04:23 +0200)
committerBenjamin Otte <otte@redhat.com>
Mon, 26 Mar 2018 16:16:36 +0000 (18:16 +0200)
This is the equivalent snapshot function to pango_cairo_show_layout().

Not to be confused with gtk_snapshot_render_layout(), which is the
equivalent to gtk_render_layout().

docs/reference/gtk/gtk4-sections.txt
gtk/gskpango.c
gtk/gskpango.h
gtk/gtksnapshot.c
gtk/gtksnapshot.h

index e5c06ac5e96c098a793bf98bc8329c6411c3340b..374124bc9a6abadf05b0f53cd55b2c206d556801 100644 (file)
@@ -4190,6 +4190,7 @@ gtk_snapshot_append_node
 gtk_snapshot_append_cairo
 gtk_snapshot_append_texture
 gtk_snapshot_append_color
+gtk_snapshot_append_layout
 gtk_snapshot_clips_rect
 gtk_snapshot_render_background
 gtk_snapshot_render_frame
index 1b84c71357f10ef3f075cc1f57d77c210c912402..7e7fa73ebe0c75faa629a30ddd2278d861a00328 100644 (file)
@@ -45,6 +45,7 @@ struct _GskPangoRenderer
   GtkSnapshot *snapshot;
   GdkRGBA fg_color;
   graphene_rect_t bounds;
+  char *name;
 
   /* house-keeping options */
   gboolean is_cached_renderer;
@@ -157,9 +158,9 @@ gsk_pango_renderer_show_text_glyphs (PangoRenderer        *renderer,
 
   if (gtk_snapshot_get_record_names (crenderer->snapshot))
     {
-      char name[64];
-      g_snprintf (name, sizeof (name), "Glyphs<%d>", glyphs->num_glyphs);
-      gsk_render_node_set_name (node, name);
+      char *s = g_strdup_printf ("%s<%d>", crenderer->name, glyphs->num_glyphs);
+      gsk_render_node_set_name (node, s);
+      g_free (s);
     }
 
   gtk_snapshot_append_node_internal (crenderer->snapshot, node);
@@ -427,6 +428,7 @@ release_renderer (GskPangoRenderer *renderer)
   if (G_LIKELY (renderer->is_cached_renderer))
     {
       renderer->snapshot = NULL;
+      g_clear_pointer (&renderer->name, g_free);
 
       G_UNLOCK (cached_renderer);
     }
@@ -434,12 +436,24 @@ release_renderer (GskPangoRenderer *renderer)
     g_object_unref (renderer);
 }
 
-/* convenience wrappers using the default renderer */
-
+/**
+ * gtk_snapshot_append_layout:
+ * @snapshot: a #GtkSnapshot
+ * @layout: the #PangoLayout to render
+ * @color: the foreground color to render the layout in
+ * @name: (transfer none): a printf() style format string for the name for the new node
+ * @...: arguments to insert into the format string
+ *
+ * Creates render nodes for rendering @layout in the given foregound @color
+ * and appends them to the current node of @snapshot without changing the
+ * current node.
+ **/
 void
-gsk_pango_show_layout (GtkSnapshot   *snapshot,
-                       const GdkRGBA *fg_color,
-                       PangoLayout   *layout)
+gtk_snapshot_append_layout (GtkSnapshot            *snapshot,
+                            PangoLayout            *layout,
+                            const GdkRGBA          *color,
+                            const char             *name,
+                            ...)
 {
   GskPangoRenderer *crenderer;
   PangoRectangle ink_rect;
@@ -450,7 +464,17 @@ gsk_pango_show_layout (GtkSnapshot   *snapshot,
   crenderer = acquire_renderer ();
 
   crenderer->snapshot = snapshot;
-  crenderer->fg_color = *fg_color;
+  crenderer->fg_color = *color;
+  if (name && gtk_snapshot_get_record_names (crenderer->snapshot))
+    {
+      va_list args;
+
+      va_start (args, name);
+      crenderer->name = g_strdup_vprintf (name, args);
+      va_end (args);
+    }
+  else
+    crenderer->name = NULL;
 
   pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
   graphene_rect_init (&crenderer->bounds, ink_rect.x, ink_rect.y, ink_rect.width, ink_rect.height);
index 80b80397efc86c3cb24300dce54373fd021757b4..a97fdebea4f6f0e31a3f3eebec416944aa35a4a3 100644 (file)
@@ -34,10 +34,6 @@ typedef struct _GskPangoRendererClass   GskPangoRendererClass;
 
 GType gsk_pango_renderer_get_type (void) G_GNUC_CONST;
 
-void gsk_pango_show_layout (GtkSnapshot   *snapshot,
-                            const GdkRGBA *fg_color,
-                            PangoLayout   *layout);
-
 G_END_DECLS
 
 #endif /* __GSK_PANGO_H__ */
index 3299c4ccdcb27a96769c7441b312b8c9007055e0..609a0c6473667edde94d8215100881cdcf0d7729 100644 (file)
@@ -1728,7 +1728,7 @@ gtk_snapshot_render_layout (GtkSnapshot     *snapshot,
   shadows_value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
   has_shadow = gtk_css_shadows_value_push_snapshot (shadows_value, snapshot);
 
-  gsk_pango_show_layout (snapshot, fg_color, layout);
+  gtk_snapshot_append_layout (snapshot, layout, fg_color, "RenderLayout");
 
   if (has_shadow)
     gtk_snapshot_pop (snapshot);
index c8003956fecb42bdcbdbe91510330f81d12c4798..db9d4e6d7860b2c564c2930ab83848e3cfaa6dd1 100644 (file)
@@ -155,6 +155,14 @@ void            gtk_snapshot_append_color               (GtkSnapshot
                                                          const graphene_rect_t  *bounds,
                                                          const char             *name,
                                                          ...) G_GNUC_PRINTF (4, 5);
+/* next function implemented in gskpango.c */
+GDK_AVAILABLE_IN_ALL
+void            gtk_snapshot_append_layout              (GtkSnapshot            *snapshot,
+                                                         PangoLayout            *layout,
+                                                         const GdkRGBA          *color,
+                                                         const char             *name,
+                                                         ...) G_GNUC_PRINTF (4, 5);
+
 
 GDK_AVAILABLE_IN_ALL
 gboolean        gtk_snapshot_clips_rect                 (GtkSnapshot            *snapshot,